package br.com.escolaespacocrianca.fineec.business;

import java.util.List;

import org.hibernate.Session;

import br.com.caelum.vraptor.ioc.Component;
import br.com.escolaespacocrianca.fineec.model.Sponsor;

@Component
public class SponsorBusiness extends EntityBusiness<Sponsor>  {
		
	public SponsorBusiness(Session session) {
		super(session, new Sponsor());
	}

	@SuppressWarnings("unchecked")
	public List<Sponsor> searchByName(String sponsorName) {

		List<Sponsor> sponsors = session.createQuery(
				"from Sponsor as s where upper(s.name) like  '%" + sponsorName.toUpperCase() + "%' and s.deleted = false").list();

		return sponsors;
	}

	@Override
	protected void updateEntityInformations(Sponsor sponsor, Sponsor sponsorToUpdate) {
		sponsorToUpdate.setName( sponsor.getName());
		sponsorToUpdate.setOccupation(sponsor.getOccupation());
		sponsorToUpdate.setCompanyName(sponsor.getCompanyName());
		sponsorToUpdate.setAddress(sponsor.getAddress());
		sponsorToUpdate.setDocuments(sponsor.getDocuments());
		sponsorToUpdate.setEmail(sponsor.getEmail());
		sponsorToUpdate.setPhoneInfoPrimary(sponsor.getPhoneInfoPrimary());
		sponsorToUpdate.setPhoneInfoSecundary(sponsor.getPhoneInfoSecundary());
	}

	@Override
	protected void beforeDelete(Sponsor t) {
		// TODO Auto-generated method stub
		
	}
}
